import React from 'react'
import { Table, Icon, Switch, Radio, Form, Divider, Popconfirm,Pagination,Button,Badge } from 'antd';
import {inject, observer} from "mobx-react/index";
import Tip from "../../common/tip"

@inject("store")
@observer
class InformList extends React.Component {
    componentDidMount = () => {
        this.props.store.actions.getInform(this.props.status)
    }
    componentWillReceiveProps(nextProps) {
        if(nextProps.status!=this.props.status)
             this.props.store.actions.getInform(nextProps.status)
    }
    onSelectChange = (selectedRowKeys) => {
        this.props.store.actions.setSelectKeys(selectedRowKeys);
    }
    render(){
        let store = this.props.store
        const list=store.informs.slice()
        const selectedRowKeys=store.selectedRowKeys
        const page=store.page
        const columns = [{
            title: '标题',
            dataIndex: 'title',
            key: 'Name',
            render: (text,record) =>record.notifyStatus===0?<div><Badge status="success" />{text}</div>:<div>{text}</div>,
        }, {
            title: '发送时间',
            dataIndex: 'createTime',
            key: 'createTime',
        },{
            title: '通知类型',
            dataIndex: 'notifyType',
            key: 'notifyType',
        }];
        const rowSelection = {
            selectedRowKeys,
            onChange: this.onSelectChange,
        };
        const footer=()=>{
            return (
                <span style={{color:"#888",fontSize:"12px"}}>共{store.total}条数据，每页显示{page.pageSize}条</span>
            )
        }
        return(
            <div>
                {list.map((item)=><div style={{display:"none"}}>{item.notifyStatus}</div>)}
                <Tip title={this.props.status==="notRead"?"未读消息":"全部消息"}/>
                <Button type="primary" onClick={()=>store.actions.deleteInform()} style={{marginBottom:"10px"}}>删除</Button>
                <Table
                    rowSelection={rowSelection}
                    columns={columns}
                    expandedRowRender={record => <p style={{ margin: 0 }}>{record.notifyContent}</p>}
                    onExpand={(expanded,record)=>store.actions.setView(expanded,record)}
                    dataSource={list.slice()}
                    pagination={{
                        total: store.total,
                        pageSize: page.pageSize,
                        defaultPageSize: page.pageSize,
                        onChange:(page)=>store.actions.setCurrentPage(this.props.status,page)
                    }}
                    footer={footer}
                />
            </div>
        )
    }
}
export default  InformList